class Solution(object):
    def maxSumAfterOperation(self, nums):
        last0 = 0
        last1 = 0
        max_val = - float('inf')
        for num in nums:
            last1 = max(last0 + num ** 2, last1 + num)
            last0 = max(last0 + num, 0)
            max_val = max(max_val, last0, last1)
        return max_val